/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.logic.facade;

import com.edu.kamai.exception.PaperAnswerAddFailException;
import com.edu.kamai.persistence.beans.PaperAnswer;
import com.edu.kamai.persistence.dao.PaperAnswerDao;
import java.util.List;

/**
 *
 * @author xyzhu
 */
public class PaperAnswerFacade {
    public static int addPaperAnswer(PaperAnswer paBean) 
            throws PaperAnswerAddFailException{
        PaperAnswerDao paperanswerdao = new PaperAnswerDao();
        paperanswerdao.addPaperAnswer(paBean);
        return 1;
    }
    
    public static List<PaperAnswer> chekPendingList(){
        PaperAnswerDao paperanswerdao = new PaperAnswerDao();
        return paperanswerdao.getPendingAnswer();
    }
    
    public static PaperAnswer getAnswerPaper(int aid){
        PaperAnswerDao paperanswerdao = new PaperAnswerDao();
        return paperanswerdao.getPendingAnswerByID(aid);
    }
    
    public static int updatePaper(int aid, String teachername,int score){
        PaperAnswerDao paperanswerdao = new PaperAnswerDao();
        PaperAnswer pa = paperanswerdao.getPendingAnswerByID
                (aid);
        if(null == pa){
            return 0;
        }
        pa.setTeacherId(teachername);
        pa.setScore(score);
        pa.setPending(1);
        paperanswerdao.updateAnswerPaper(pa);
        return 1;      
    }
    
    public static List<PaperAnswer> getAnswerScoreByContestIDAndUserID
            (int cid,String uid){
        PaperAnswerDao paperanswerdao = new PaperAnswerDao();
        return paperanswerdao.getAnswerScoreByContestIDAndUserID(cid, uid);
    }
}
